﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Polaris.Domain.Interfaces.Admin;
using Polaris.Domain.Model.Dto.Article.Request;
using Polaris.Domain.Model.Dto.Notes.Request;
using Polaris.Domain.Model.Dto.Permissions.Response;

namespace Polaris.WebApi.Controllers.Admin
{
    /// <summary>
    /// 闲书控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class NotesController : BaseController
    {
        private readonly INotes _notes;

        public NotesController(INotes notes)
        {
            _notes = notes;
        }

        /// <summary>
        /// 创建闲书
        /// </summary>
        /// <param name="create"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> CreateNotes(CreateNotesInfoRequest create)
        {
            await _notes.CreateNotes(create, null);
            return SUCCESS("OK");
        }

        /// <summary>
        /// 获取闲书列表
        /// </summary>
        /// <param name="quyer"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetNotesList([FromQuery] NotesQueryRequest quyer)
        {
            var result = await _notes.GetNotesList(quyer);
            return SUCCESS(result);
        }

        /// <summary>
        /// 根据id获取闲书内容
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetNotesContentById(string id)
        {
            var result = await _notes.GetNotesContentById(id);
            return SUCCESS(result);
        }

        /// <summary>
        /// 根据id获取闲书
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetNotesById(string id)
        {
            var result = await _notes.GetNotesById(id);
            return SUCCESS(result);
        }

        /// <summary>
        /// 修改闲书
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdateNotes(NotesInfoResponse update)
        {
            await _notes.UpdateNotes(update, null);
            return SUCCESS("操作成功");
        }

        /// <summary>
        /// 删除闲书
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DeleteById(string id)
        {
            await _notes.DeleteById(id, null);
            return SUCCESS("操作成功");
        }
    }
}
